<template>
    <div class="redact">
        <div class="rl">
            <span class="xk">学科：</span>
            <el-input class="input" v-model="input" placeholder="请输入内容"></el-input>
        </div>
        <div class="ybn">
            <span class="nj">年级：</span>
            <el-select v-model="value" placeholder="请选择">
                <el-option v-for="item in options" :key="item.value" :label="item.value" @click.native="levelQ(item.label)" :value="item.value">
                </el-option>
            </el-select>
        </div>
        <div class="dj">
            <el-button type="primary" @click="submit">提交</el-button>
            <el-button class="an" @click="reset">重置</el-button>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            input: '',
            options: [
                {
                    label: '1',
                    value: '一年级'
                },
                {
                    label: '2',
                    value: '二年级'
                },
                {
                    label: '3',
                    value: '三年级'
                },
                {
                    label: '4',
                    value: '四年级'
                },
                {
                    label: '5',
                    value: '五年级'
                },
                {
                    label: '6',
                    value: '六年级'
                },
                {
                    label: '7',
                    value: '初一'
                },
                {
                    label: '8',
                    value: '初二'
                },
                {
                    label: '9',
                    value: '初三'
                },
                {
                    label: '10',
                    value: '高一'
                },
                {
                    label: '11',
                    value: '高二'
                },
                {
                    label: '12',
                    value: '高三'
                }
            ],
            value: '一年级',
            row1: JSON.parse(window.sessionStorage.getItem('row')),
            level:1
        }
    },
    methods: {
        // 提交
        submit() {
            if (this.row1 === true) {
                this.axios({
                    method: "post",
                    url: "/api/admin/education/subject/edit",
                    data: {
                        "name": this.input,
                        "level":this.level,
                        "levelName": this.value
                    }
                }).then(res=>{
                    console.log(res);
                })
            } else {
                this.axios({
                    method: "post",
                    url: "/api/admin/education/subject/edit",
                    data: {
                        "id":this.row1.id,
                        "name": this.input,
                        "level":this.level,
                        "levelName": this.value
                    }
                }).then(res=>{
                    console.log(res);
                })
            }
            // console.log(this.value);
            this.$router.back() 
        },
        // 获取level值
        levelQ(level){
            this.level = level
        },
        // 重置
        reset(){
            this.input = ""
            this.value = "一年级"
        }
    },
    mounted() {
        // 页面挂载时做的
        if (this.row1 === true) {
            this.input = " "
            this.value = "一年级"
        } else {
            this.input = this.row1.name
            this.value = this.row1.levelName
        }
    }
}
</script>

<style lang="scss" scoped>
.redact {
    width: 100%;
    padding: 30px 0 0 35px;
    box-sizing: border-box;

    .xk {
        display: inline-block;
    }

    .rl {
        width: 90%;
    }

    .input {
        width: 90%;
    }

    .ybn {
        margin-top: 15px;
    }

    .nj {
        font-size: 15px;
        font-weight: 100;
        display: inline-block;
    }

    .dj {
        margin-top: 15px;
    }
}
</style>